package com.itheima.health.controller;

import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.service.SetmealService;
import com.itheima.health.utils.resources.MessageConstant;
import com.itheima.health.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(value = "微信预约服务")
public class SetmealMobileController {

    @Reference
    private SetmealService setmealService;

    /**
     * 查询所有套餐
     * @return
     */
    @GetMapping("setmeal/findAll")
    @ApiOperation(value = "查询所有套餐的方法",notes = "查询所有套餐")
    public Result findSetmealAll(){
        try {
            List<Setmeal> setmealList = setmealService.list();
            System.out.println(setmealList.get(0).getImg());
            return new Result(true, MessageConstant.QUERY_SETMEALLIST_SUCCESS,setmealList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_SETMEALLIST_FAIL);
        }

    }

    @GetMapping("setmeal/findSetmealDetail/{id}")
    @ApiOperation(value = "查询套餐预约详情的方法",notes = "根据id查询套餐预约详情")
    public Result findSetmealDetail(@PathVariable("id") int id){
        try{
            SetmealVO setmealVO = setmealService.findSetmealDetail(id);
            return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,setmealVO);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }

    @GetMapping("setmeal/findSetmeal/{id}")
    @ApiOperation(value = "查询套餐详情的方法",notes = "编辑页面根据id查询套餐详情")
    public Result findSetmeal(@PathVariable("id")int id){
        try{
            SetmealVO setmealVO = setmealService.findSetmealDetail(id);
            return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,setmealVO);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }
}

